package cn.com.fuhuitong.main.mine.mode

import android.provider.ContactsContract
import cn.com.fuhuitong.http.BaseAbstractManager
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.ResponseSubscribeListener
import cn.com.fuhuitong.http.SubscribeListener
import cn.com.fuhuitong.main.access.entity.UserResponse
import cn.com.fuhuitong.main.home.entity.HomeResponse
import cn.com.fuhuitong.main.host.mode.MainApi
import cn.com.fuhuitong.main.mine.entity.*
import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import retrofit2.http.Query

class MineManager : BaseAbstractManager<MineApi>(MineApi::class.java) {

    /**
     * 获取地址列表
     */
    fun addressList(token: String, listener: SubscribeListener<AddressListResponse>): Disposable {
        val addressList: Observable<AddressListResponse> = apiService.addressList(token)
        return subscribe(addressList, ResponseSubscribeListener(listener))
    }

    /**
     * 添加地址
     */
    fun addressAdd(
        token: String, address: AddressAddEntity,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val addressAdd: Observable<BaseResponse> = apiService.addressAdd(token, address)
        return subscribe(addressAdd, ResponseSubscribeListener(listener))
    }

    /**
     * 修改地址
     */
    fun addressEdit(
        token: String, address: AddressAddEntity,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val addressEdit: Observable<BaseResponse> = apiService.addressEdit(token, address)
        return subscribe(addressEdit, ResponseSubscribeListener(listener))
    }

    /**
     * 分享配置
     */
    fun share(
        token: String, listener: SubscribeListener<MineShareResponse>
    ): Disposable {
        val addressList: Observable<MineShareResponse> = apiService.share(token)
        return subscribe(addressList, ResponseSubscribeListener(listener))
    }


    /**
     * 分享中心
     */
    fun distributionCenter(
        token: String, listener: SubscribeListener<MineShareCenterResponse>
    ): Disposable {
        val distributionCenter: Observable<MineShareCenterResponse> =
            apiService.distributionCenter(token)
        return subscribe(distributionCenter, ResponseSubscribeListener(listener))
    }

    /**
     * 申请提现
     */
    fun addCash(
        token: String, entity: WithdrawEntity,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val addCash: Observable<BaseResponse> =
            apiService.addCash(token, entity)
        return subscribe(addCash, ResponseSubscribeListener(listener))
    }

    /**
     * 申请提现
     */
    fun addStoreCash(
        token: String, entity: WithdrawEntity,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val addCash: Observable<BaseResponse> =
            apiService.addStoreCash(token, entity)
        return subscribe(addCash, ResponseSubscribeListener(listener))
    }

    /**
     * 提现记录
     */
    fun cashList(
        token: String, page: String, limit: String,
        listener: SubscribeListener<WithdrawListResponse>
    ): Disposable {
        val cashList: Observable<WithdrawListResponse> =
            apiService.cashList(token, page, limit)
        return subscribe(cashList, ResponseSubscribeListener(listener))
    }

    /**
     * 提现记录
     */
    fun cashStoreList(
        token: String, page: String, limit: String,
        listener: SubscribeListener<WithdrawListResponse>
    ): Disposable {
        val cashList: Observable<WithdrawListResponse> =
            apiService.cashStoreList(token, page, limit)
        return subscribe(cashList, ResponseSubscribeListener(listener))
    }

    /**
     * 提现配置
     */
    fun cashPrice(
        token: String, listener: SubscribeListener<WithdrawConfigResponse>
    ): Disposable {
        val cashPrice: Observable<WithdrawConfigResponse> =
            apiService.cashPrice(token)
        return subscribe(cashPrice, ResponseSubscribeListener(listener))
    }

    /**
     * 提现配置
     */
    fun cashStorePrice(
        token: String, listener: SubscribeListener<WithdrawConfigResponse>
    ): Disposable {
        val cashPrice: Observable<WithdrawConfigResponse> =
            apiService.cashStorePrice(token)
        return subscribe(cashPrice, ResponseSubscribeListener(listener))
    }

    /**
     * 我的收藏
     */
    fun goodsCollection(
        token: String, page: String, limit: String,
        listener: SubscribeListener<CollectionListResponse>
    ): Disposable {
        val goodsCollection: Observable<CollectionListResponse> =
            apiService.goodsCollection(token, page, limit)
        return subscribe(goodsCollection, ResponseSubscribeListener(listener))
    }

    /**
     * 删除收藏
     * */
    fun delGoodsCollection(
        token: String, goodsCollectionId: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val delGoodsCollection: Observable<BaseResponse> =
            apiService.delGoodsCollection(token, goodsCollectionId)
        return subscribe(delGoodsCollection, ResponseSubscribeListener(listener))
    }

    /**
     *个人中心订单数量标识
     * */
    fun orderSign(
        token: String, listener: SubscribeListener<OrderSignResponse>
    ): Disposable {
        val orderSign: Observable<OrderSignResponse> =
            apiService.orderSign(token)
        return subscribe(orderSign, ResponseSubscribeListener(listener))
    }

    /**
     * 修改昵称
     * */
    fun editUserNickname(
        token: String, nickname: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val editUserNickname: Observable<BaseResponse> =
            apiService.editUserNickname(token, nickname)
        return subscribe(editUserNickname, ResponseSubscribeListener(listener))
    }

    /**
     * 获取个人信息
     * */
    fun getUserInfo(
        token: String, listener: SubscribeListener<UserResponse>
    ): Disposable {
        val getUserInfo: Observable<UserResponse> =
            apiService.getUserInfo(token)
        return subscribe(getUserInfo, ResponseSubscribeListener(listener))
    }

    /**
     * 收益中心
     * */
    fun orderStoreCommission(
        token: String, listener: SubscribeListener<MineIncomeCenterResponse>
    ): Disposable {
        val getUserInfo: Observable<MineIncomeCenterResponse> =
            apiService.orderStoreCommission(token)
        return subscribe(getUserInfo, ResponseSubscribeListener(listener))
    }

    /**
     * 收益中心列表
     * */
    fun orderStoreOrder(
        token: String,
        page: String,
        limit: String,
        listener: SubscribeListener<MineIncomeListResponse>
    ): Disposable {
        val getUserInfo: Observable<MineIncomeListResponse> =
            apiService.orderStoreOrder(token, page, limit)
        return subscribe(getUserInfo, ResponseSubscribeListener(listener))
    }

}